angular.module('start.user.friend.fanslist.ctrl', [])

  .controller('friendfanslistCtrl', function($scope, $timeout, $$UserFriendService, $rootScope, $stateParams, $location, $ionicLoading) {
    console.log("friendfanslistCtrl");

    $scope.fanslist = [];

    $scope.pageData = {
      isloading: true,
      pageSize: 10,
      pageNum: 1,
      nomoreData: false
    };

    $scope.pageData.isloading = true;
    $$UserFriendService.getfriendfanslist(1, 10)
      .then(function(res) {
        $scope.fanslist = res.data;
      });


    $scope.getfansPageList = function() {
      $scope.pageData.isloading = true;
      $$UserFriendService.getfriendfanslist(1, 10)
        .then(function(res) {
          if (res.data == null || res.data == undefined) {
            res.data = [];
          }
          if (res.errCode === 203) {
            $scope.fanslist = $scope.fanslist.concat(res.data);
            $scope.$broadcast('scroll.infiniteScrollComplete');
            // 如果没有更多数据 数据到底了
            $scope.pageData.pageNum++;
            if (res.data.length < $scope.pageData.pageSize) {
              $scope.pageData.nomoreData = true;
            } else {
              $scope.pageData.nomoreData = false;
            }
          } else {
            $ionicLoading.show({
              template: res.msg,
              noBackdrop: true,
              duration: 1500
            });
          }
          $scope.pageData.isloading = false;
        }, function(err) {
          $scope.pageData.isloading = false;
        });
    };
    $scope.getfansPageList();

  });
